﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询系统授权列表</title>
<!-- 加载公共的样式，主要作用是清除浏览器的一些默认样式，页面公共排版，包括头部以及一些组件样式   -->
<link type="text/css" rel="stylesheet" href="${ctx}/css/base.css" />
<link type="text/css" rel="stylesheet" href="${ctx}/css/index.css" />

<!-- 前端框架核心库加载放在 -->
<script src="${ctx}/js/lib/core.js" type="text/javascript"></script>
<script src="${ctx}/js/component/modal.js" type="text/javascript"></script>
<!-- 加载树-->
<%@ include file="/include/zTree.jsp" %>
<!-- 模块化框架配置 -->
<script type="text/javascript">
    // seajs 的简单配置
    seajs.config({
        base: "${ctx}/js",
        alias: {

        }
    });
</script>
<script type="text/javascript" src="${ctx}/js/index.js"></script>

</head>
<body>
	<div id="menuContent" class="menuContent" style="display:none; position: absolute;background-color: white;">
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:160px;"></ul>
	</div>
		<div class="main">
  		<div class="b_box">
        <div class="p_bar">您当前的位置：权限管理</div>
		<input type="hidden" id="authorityId" name="authorityId"/>
		<table class="c_table m_t10">
			<tr>
				<!-- 查询条件 -->
				<td width="10%" class="t_tit">权限：</td>
				<td width="30%">
					<input type="text" id="parentName" readonly="readonly" class="input_txt"/>
					<a href="javascript:showMenu();">选择</a>&nbsp;&nbsp;<a href="javascript:clear();">清除</a>
					<input type="hidden" name="parentAuthorityName" id="parentId"/>
				</td>
				<td width="10%"  class="t_tit">权限名称：</td>
				<td width="30%">
				<input type="text" id="authorityName" name="authorityName" class="input_txt"/>
				<input type="button" value="查询" id="searchBtn" class="a_btn"/>
				</td>
				<td width="20%"></td>
			</tr>
		</table>
		</div>
		<div class="action_box m_t10 t_r">
			<span class="action_tit">系统权限信息</span>
			<input type="button" class="b_btn" value="新增" id="addBtn"/>
		</div>
		<table id="tbwrap" class="table_list"></table>
		<div class="page eui-pager-custom" id="j_pager">
	</div>
	</div>
		<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th>权限名称</th>
				<th>权限值</th>
				<th>父级权限</th>
				<th>权限类型</th>
				<th>状态</th>
				<th>控制的事件</th>
				<th>等级</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td title="<!=item["authorityName"]!>"><!=item["authorityName"]!></td>
					<td title="<!=item["authorityValue"]!>"><!=item["authorityValue"]!></td>
					<td title="<!=item["parentAuthorityName"]!>"><!=item["parentAuthorityName"]!></td>
					<td title="<!=item["authorityTypeName"]!>"><!=item["authorityTypeName"]!></td>
					<td title="<!=item["statusName"]!>"><!=item["statusName"]!></td>
					<td title="<!=item["action"]!>"><!=item["action"]!></td>
					<td title="<!=item["grade"]!>"><!=item["grade"]!></td>
					<td>
						<hna:permission privilege="sysAuthority.view">
							<a title="详情" data-value="<!=item["authorityId"]!>" class="detail">详情</a>&nbsp;
						</hna:permission>
						<hna:permission privilege="sysAuthority.edit">
							<a title="修改" data-value="<!=item["authorityId"]!>" class="edit">修改</a>&nbsp;
						</hna:permission>
						<hna:permission privilege="sysAuthority.delete">
							<a title="删除" data-value="<!=item["authorityId"]!>" class="delete">删除</a>
						</hna:permission>
					</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="10"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>


	<script type="text/javascript">
		var sysAuthorityDialog;
		var allAuthority="";
		$(function(){
			// 1、添加
			$("#addBtn").click(function(){
				seajs.use("component/dialog", function (dialog) {
				    sysAuthorityDialog = new dialog({
				        "width" : 800,
				        "height" : 530,
				        "contentType" : "iframe",
						"html" : "${ctx}/sysAuthority/toAdd", // 内容
				        "title" : "添加系统授权信息" //标题
					});
				});
			});
			// 2、详细
			$("#tbwrap").delegate(".detail", "click", function () {
				// 2.1 获取主键
				var authorityId = $(this).data("value");
				// 2.2 弹窗窗口，显示详细信息
				seajs.use("component/dialog", function (dialog) {
				    sysAuthorityDialog = new dialog({
				        "width" : 800,
				        "height" : 375,
				        "contentType" : "iframe",
						"html" : "${ctx}/sysAuthority/view?authorityId="+authorityId, // 内容
				        "title" : "查看系统授权详细信息" //标题
					});
				});
			});
			// 3、编辑
			$("#tbwrap").delegate(".edit", "click", function () {
				// 3.1 获取主键
				var authorityId = $(this).data("value");
				// 3.2 弹窗窗口，显示详细信息
				seajs.use("component/dialog", function (dialog) {
				    sysAuthorityDialog = new dialog({
				        "width" : 800,
				        "height" : 530,
				        "contentType" : "iframe",
						"html" : "${ctx}/sysAuthority/toEdit?authorityId="+authorityId, // 内容
				        "title" : "编辑系统授权详细信息" //标题
					});
				});
			});
			// 4、删除
			$("#tbwrap").delegate(".delete", "click", function () {
				var authorityId = $(this).data("value");
				if (confirm('确定删除？')) {
					$.post("${ctx}/sysAuthority/delete", {
							authorityId : authorityId,
							csrfToken:"${csrfToken}"
						}, function (result) {
			            if ("succ" == result) {
			            	alert("操作成功");
							// 刷新列表页面
			                self.location.replace("${ctx}/sysAuthority/list?ts="+new Date().getTime()); //如果操作成功则跳到列表界面
							// 关闭弹窗窗口
			    			parent.sysAuthorityDialog.close();
			            }else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) {// 如果不通过安全检查
			                var mess = result["mess"];
			                $.post("${ctx}/common/notThroughSecurityCheck?ts="+new Date().getTime(), mess, function(res){
			                    alert(res);
			                },"json");
			            }else {
			            	alert(result);
			            }
			        }, "json");
				}
				
			});
			// 5、查询
			$("#searchBtn").click(function () {
				search();
	        });
		});
	
	</script>
	
	<script type="text/javascript">
		$(function () {
	        initTree();
	    	$("#parentName").click(function(){
				showMenu();
			});
			
	    });
		
		function search() {
	        seajs.use(["component/table"], function (uiTable) {
		        $.post("${ctx}/sysAuthority/ajaxPage",
		        {
		        	page: 1,
		        	authorityName: $("#authorityName").val(),
		        	authorityId: $("#authorityId").val()
		        	// 其他查询条件
		        }, function (result) {
		        	// alert("status="+result.status+", currentPage="+result.currentPage+", pageCount="+result.pageCount+", rowCount="+result.rowCount);
	            	var table = new uiTable({
	                	"con": "#tbwrap",
	                    "data": {
	                         "list": result.dataList
	                    },
	                    "template": "tb_template",
	                    "pager": {
	                    	"con": "#j_pager",
	                        "data": {
	                        	"currentPage": result.currentPage,
	                            "pageCount": result.pageCount,
	                            "rowCount": result.rowCount
	                        },
	                        template: '<a title="首页" class="page_first" data-role="first" href="#"></a><a title="上一页" class="page_prev" href="#" data-role="prev"></a><div data-value="pageNum"></div><a title="下一页" class="page_next" href="#" data-role="next"></a><a title="尾页" class="page_last" href="#" data-role="last"></a> 共<span data-target="rowCount"></span>条 跳转到 <input type="text" data-target="input" class="page_input"/><a href="#" data-role="go" class="go">GO</a>'
	                    }
	                });

	                table.getPager().bind("changePage", function (event, page, hander) {
	                	$.post("${ctx}/sysAuthority/ajaxPage", {
	                			page: page,
	                			authorityName: $("#authorityName").val(),
	        		        	authorityId: $("#authorityId").val()
	                	},
	                    function (result) {
	                    	table.render({ "list": result.dataList });
		                    hander({"currentPage": result.currentPage, "pageCount": result.pageCount, "rowCount": result.rowCount });
		                    easyUtils.fullRows("queryTable",8);
	                	}, "json");
	                });
	                easyUtils.fullRows("queryTable",8);
	        	}, "json");
	      	});
		}
	</script>

	<script type="text/javascript">
		function clear() {
			$("#parentName").val("");
			$("#parentId").val("");
			$("#authorityId").val(allAuthority);
		}
		function showMenu() {
			var cityObj = $("#parentName");
			var cityOffset = $("#parentName").offset();
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
	
			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
		
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getSelectedNodes();
			
			if(nodes.length > 0) {
				var parentNameObj = $("#parentName");
				parentNameObj.attr("value", nodes[0].name);
				var parentIdObj = $("#parentId");
				parentIdObj.attr("value", nodes[0].id);
				$("#authorityId").val(nodes[0].diyParams)
			}
			hideMenu();
		}
		function initTree(){
			var setting = { 
				data: { 
					simpleData: { 
						enable: true 
					} 
					} ,
				view:{showLine:false},
				async: { 
					enable: true, 
					url:"${ctx}/sysAuthority/authorityMenuTree",
					autoParam:["id"], 
					dataType: "json",//默认text 
					dataFilter: filter //异步返回后经过Filter 
					},
				callback:{ 
					onAsyncSuccess: zTreeOnAsyncSuccess,//异步加载成功的fun 
					asyncError: zTreeOnAsyncError, //加载错误的fun 
					onClick:onClick
				} }; 
			
				//treeId是treeDemo 
				function filter(treeId, parentNode, childNodes) { 
					if (!childNodes) return null; 
						for (var i=0, l=childNodes.length; i<l; i++) { 
							childNodes[i].name = childNodes[i].name.replace('',''); 
					} 
						return childNodes; 
				}
				
				function beforeClick(treeId,treeNode){ 
					if(!treeNode.isParent){ 
						//alert("请选择父节点"); 
						return false; 
					}else{ 
						return true; 
					} 
				} 
				function zTreeOnAsyncError(event, treeId, treeNode){ 
					alert("异步加载失败!"); 
				} 
				function zTreeOnAsyncSuccess(event, treeId, treeNode, msg){ 
					allAuthority=zTree.getNodes()[0].diyParams;
					$("#authorityId").val(allAuthority);
			        search();
				} 
				$.fn.zTree.init($("#treeDemo"),setting);
				zTree = $.fn.zTree.getZTreeObj("treeDemo");
	}
	</script>
</body>
</html>
